<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<script src="../js/common.js" type="text/javascript"></script>
<script type="text/javascript">
function isExist(){
	var code = document.getElementById("code").value;
   sendRequest("/bookDeviceSys/codeIsExsit?code="+code);  
}  

function ischeck(){
	var c = document.getElementsByName("device.isShowImage");
	if(c[0].checked || c[1].checked || c[2].checked || c[3].checked || c[4].checked || c[5].checked){
		document.form1.submit();
	}else{
		alert("请选择一张图片作为默认展示图片");
		c[0].focus();
	};
	
}

function handleResponse() {
   if (XMLHttpReq.readyState == 4) {
      if (XMLHttpReq.status == 200) {
           var res = XMLHttpReq.responseXML;  
           var response= res.getElementsByTagName("response")[0].firstChild.nodeValue;
       	   if("exsit" == response){
      			document.getElementById("exsit").innerHTML = "<font color=red size=2px>该设备Id已存在</font>";
      			document.getElementById("commit").disabled = "disabled";
           }else{
        		document.getElementById("exsit").innerHTML = "<font color=green size=2px>该设备ID可用</font>";
        		document.getElementById("commit").disabled = "";
        	}
 	   };
   };
}
</script>
<link href="../css/common.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<%!String action = null;%>
<%if("yes".equals(String.valueOf(request.getAttribute("isUpdate")))){
	action = "/bookDeviceSys/device/device!update.action";
}else{
	action = "/bookDeviceSys/device/device!add.action";
}%>

<form action="<%=action%>" method="post" enctype="multipart/form-data" name="form1">
<table align="center" width="75%"  id="mytable">
	<tr>
		<td align="center"  width="20%">设备ID</td>
		<td>
			<%if("yes".equals(String.valueOf(request.getAttribute("isUpdate")))){ %>
			<input type="text" name="device.code" value="${deviceVo.code}" readonly="readonly"/>
			<%}else{ %>
			<input type="text" name="device.code" value="${deviceVo.code}" onblur="isExist()" id="code"/>
			<%} %>
		<div id="exsit"></div>
		</td>
	</tr>
	<tr>
		<td align="center">设备名称</td>
		<td>
			<input type="text" name="device.name" value="${deviceVo.name}"/>
		</td>
	</tr>
	<tr>
		<td align="center">图片</td>
		<td>
		<%if("yes".equals(String.valueOf(request.getAttribute("isUpdate")))){ %>
		<%for(int i = 0 ;i<6;i++){%>
		<img width="120px" height="120px" src="/bookDeviceSys/searchImage?did=${deviceVo.code}&showAll=true&index=<%=i%>" onerror="this.style.display='none'">
		<%}%>
		<%}else{%>
		<input type="file" name="device.imageFile" onchange="showImage()"><font size="2px">图片标题：</font><input type="text" name="device.imageFileName"/><input type="radio" name="device.isShowImage" value="1,0"/><font size="2px">是展示图片吗</font><input type="hidden" name="device.imageId"><br/>
		<input type="file" name="device.imageFile"><font size="2px">图片标题：</font><input type="text" name="device.imageFileName"><input type="radio" name="device.isShowImage" value="1,1"/><font size="2px">是展示图片吗</font> <input type="hidden" name="device.imageId"><br/>
		<input type="file" name="device.imageFile"><font size="2px">图片标题：</font><input type="text" name="device.imageFileName"><input type="radio" name="device.isShowImage" value="1,2"/><font size="2px">是展示图片吗</font><input type="hidden" name="device.imageId"><br/>
		<input type="file" name="device.imageFile"><font size="2px">图片标题：</font><input type="text" name="device.imageFileName"><input type="radio" name="device.isShowImage" value="1,3"/><font size="2px">是展示图片吗</font><input type="hidden" name="device.imageId"><br/>
		<input type="file" name="device.imageFile"><font size="2px">图片标题：</font><input type="text" name="device.imageFileName"><input type="radio" name="device.isShowImage" value="1,4"/><font size="2px">是展示图片吗</font><input type="hidden" name="device.imageId"><br/>
		<input type="file" name="device.imageFile"><font size="2px">图片标题：</font><input type="text" name="device.imageFileName"><input type="radio" name="device.isShowImage" value="1,5"/><font size="2px">是展示图片吗</font><input type="hidden" name="device.imageId">
		<%} %>
		</td>
	</tr>
	<tr>
		<td align="center">租用方式</td>
		<td>
              	<%if("00".equals(String.valueOf(request.getAttribute("updateItem-timeType")))){ %>
			 	<input type="radio" value="0" name="device.timeType" checked="checked">按天租用
			 	<input type="radio" value="1" name="device.timeType">按时租用
			 	<%}else if("1".equals(String.valueOf(request.getAttribute("updateItem-timeType")))) {%>
				<input type="radio" value="0" name="device.timeType">按天租用
			 	<input type="radio" value="1" name="device.timeType" checked="checked">按时租用
				<%}else {%>
			 	<input type="radio" value="0" name="device.timeType">按天租用
			 	<input type="radio" value="1" name="device.timeType">按时租用
			 	<%} %>
		</td>
	</tr>
	<tr>
		<td align="center">可用与否</td>
		<td>
			 	<%if("00".equals(String.valueOf(request.getAttribute("updateItem-available")))){ %>
			 	<input type="radio" name="device.available" value="0" checked="checked">不可用
			 	<input type="radio" name="device.available" value="1"/>可用
			 	<%}else if("1".equals(String.valueOf(request.getAttribute("updateItem-available")))){ %>
			 	<input type="radio" name="device.available" value="0">不可用
			 	<input type="radio" name="device.available" value="1" checked="checked"/>可用			 	
			 	<%}else{ %>
			 	<input type="radio" name="device.available" value="0">不可用
			 	<input type="radio" name="device.available" value="1"/>可用			 	
			 	<%} %>
		</td>
	</tr>
	<tr>
		<td align="center">设备描述</td>
		<td>
		<textarea rows="5" cols="50" name="device.description">${deviceVo.description}</textarea>
		</td>
	</tr>
	<tr>
		<td colspan="2"><input type="button" value="确认" onclick="ischeck()" id="commit"></td>
	</tr>
</table>

</form>
</body>
</html>